#line 1 "newfile.c"
#line 1 "newfile.c"

#line 49 "newfile.c"
 





#line 56 "newfile.c"


__CONFIG(1, 0x0200);
__CONFIG(2, 0X1E1F);
__CONFIG(3, 0X8100);
__CONFIG(4, 0X0081);
__CONFIG(5, 0XC00F);




#line 68 "newfile.c"
#line 69 "newfile.c"


#line 72 "newfile.c"
#line 73 "newfile.c"

uint8_t digits[4] = {0, 0, 0, 0};




void Wait(unsigned int delay) {
    for (; delay; delay--)
        __delay_us(100);
}

void SevenSegment(uint8_t num) {
    switch (num) {
        case 0:
            

            PORTD  = 0B00111111;
            break;

        case 1:
            
            PORTD  = 0B00000110;
            break;

        case 2:
            

            PORTD  = 0B01011011;
            break;

        case 3:
            
            PORTD  = 0B01001111;
            break;

        case 4:
            

            PORTD  = 0B01100110;
            break;

        case 5:
            
            PORTD  = 0B01101101;
            break;

        case 6:
            

            PORTD  = 0B01111101;
            break;
        case 7:
            
            PORTD  = 0B00000111;
            break;

        case 8:
            

            PORTD  = 0B01111111;
            break;

        case 9:
            
            PORTD  = 0B01101111;
            break;
    }
}

void SevenSegInit() {
    
    TRISD  = 0X00;
    TRISA  = 0B11110000;

    PORTA  = 0B00000001;

    
    T0PS0 = 1; 

    T0PS1 = 1;
    T0PS2 = 1;

    PSA = 0; 

    T0CS = 0; 

    T08BIT = 1; 

    TMR0IE = 1; 
    PEIE = 1; 

    GIE = 1; 

    TMR0ON = 1; 
}

void SevenSegPrint(uint16_t num) {
    
#line 176 "newfile.c"
 
    uint8_t i = 0;
    uint8_t j;
    if (num > 9999) return;
    while (num) {
        digits[i] = num % 10;
        i++;

        num = num / 10;
    }
    for (j = i; j < 4; j++) digits[j] = 0;
}

void SevenSegISR() {
    
#line 195 "newfile.c"
 

    TMR0 = 150;

    static uint8_t i;

    if (i == 3) {
        
        
        i = 0;

    } else
 {
        
        i++;
    }



    
    PORTA  = ((PORTA  & 0xf0) | (1 << i));

    

    SevenSegment(digits[i]);
}



void interrupt ISR() {
    
    if (TMR0IE && TMR0IF) {
        
        SevenSegISR();

        

        TMR0IF = 0;
    }
}

void main() {
    
    SevenSegInit();

    
    SevenSegPrint(1234);

    

    while (1);

}

